//! \file fileutil.hpp
//! \brief Purewell Library File Utility Header
//! \author Yubin Lim (purewell@gmail.com)
//! \since 2008-01-25

#ifndef __PWHDR_FILEUTIL_HPP__
#define __PWHDR_FILEUTIL_HPP__

#include "file.hpp"

namespace purewell
{

class PWFile;

//! \brief File utility.
class PWFileUtil
{
public:
	//! \brief Set blocking mode.
	//! \param[in] file File.
	//! \param[in] block Block mode.
	//! \return On success, true.
	bool setModeBlock(PWFile& file, bool block) const;

	//! \brief Get blocking mode.
	//! \param[in] file File.
	//! \return On blocking mode, true.
	bool getModeBlock(const PWFile& file) const;

	//! \brief Set asynchronous mode.
	//! \param[in] file File.
	//! \param[in] async Asynchronous mode.
	//! \return On success, true.
	bool setModeAsync(PWFile& file, bool async) const;

	//! \brief Get asynchronous mode.
	//! \param[in] file File.
	//! \return On asynchronous, true.
	bool getModeAsync(const PWFile& file) const;

	//! \brief Duplicate file descriptor.
	//! \param[out] dst Destination.
	//! \param[in] src Source.
	//! \return On success, true.
	bool duplicate(PWFile& dst, const PWFile& src) const;

	//! \brief Duplicate file descriptor.
	//! \param[out] dst Destination.
	//! \param[in] src Source.
	//! \param[in] newfd New file descriptor number.
	//! \return On success, true.
	bool duplicate(PWFile& dst, const PWFile& src, int newfd) const;

public:
	//! \brief Get instance.(singleton)
	//! \return Instance reference.
	static PWFileUtil& getInstance(void);

private:
	explicit PWFileUtil();
	virtual ~PWFileUtil();
};

//! \brief File utility instance.
extern PWFileUtil& gPWFileUtil;

};//namespace purewell

#endif//!__PWHDR_FILEUTIL_HPP__

